-- 代码作者：ti_Tout

local _G = GLOBAL

--------------------------------------------------------------------------
--[[ 修改默认的科技树生成方式 ]]
--------------------------------------------------------------------------
local TechTree = require("techtree")

table.insert(TechTree.AVAILABLE_TECH, "BBOY_PIGGY_HI_SHOP") -- 其实就是加个自己的科技树名称

local Create_old = TechTree.Create
TechTree.Create = function(t, ...)
    local newt = Create_old(t, ...)
    newt["BBOY_PIGGY_HI_SHOP"] = newt["BBOY_PIGGY_HI_SHOP"] or 0
    return newt
end

--------------------------------------------------------------------------
--[[ 新制作栏 ]]
--------------------------------------------------------------------------
AddRecipeFilter({ -- 拼好mod
    name = "BBOY", atlas = "images/bboy_inventoryimages.xml", image = "bboy_candle_item.tex"
})

-- 嗨猪
AddRecipeFilter({
    name = "BBOY_PIGGY_HI",
    atlas = "images/bboy_crafting_menu_icons.xml",
    image = "station_bboy_piggy_hi.tex",
    custom_pos = true
})

--------------------------------------------------------------------------
--[[ 制作等级中加入自己的部分 ]]
--------------------------------------------------------------------------
_G.TECH.NONE.BBOY_PIGGY_HI_SHOP = 0
_G.TECH.BBOY_PIGGY_HI_SHOP_ONE = { BBOY_PIGGY_HI_SHOP = 1 }

--------------------------------------------------------------------------
--[[ 解锁等级中加入自己的部分 ]]
--------------------------------------------------------------------------
-- BBOY_PIGGY_HI_SHOP_ONE 可以改成任意的名字,这里和 TECH.BBOY_PIGGY_HI_SHOP_ONE 名字相同只是懒得改了
TUNING.PROTOTYPER_TREES.BBOY_PIGGY_HI_SHOP_ONE = TechTree.Create({
    BBOY_PIGGY_HI_SHOP = 1,
})

--------------------------------------------------------------------------
--[[ 修改全部制作配方，对缺失的值进行补充 ]]
--------------------------------------------------------------------------
for i, v in pairs(AllRecipes) do
    if v.level.BBOY_PIGGY_HI_SHOP == nil then
        v.level.BBOY_PIGGY_HI_SHOP = 0
    end
end


--------------------------------------------------------------------------
--[[ 让某个制作栏分类能显示全部对象，不管能不能解锁或制作 ]]
--------------------------------------------------------------------------
if not TheNet:IsDedicated() then
    local craftingmenu_widget = require "widgets/redux/craftingmenu_widget"

    local ApplyFilters_old = craftingmenu_widget.ApplyFilters
    craftingmenu_widget.ApplyFilters = function(self, ...)
        if
            (self.current_filter_name == "BBOY") and
            CRAFTING_FILTERS[self.current_filter_name] ~= nil
        then
            self.filtered_recipes = {}
            local filter_recipes = FunctionOrValue(CRAFTING_FILTERS[self.current_filter_name].default_sort_values) or nil
            if filter_recipes == nil then
                return ApplyFilters_old(self, ...)
            end
            for i, recipe_name in metaipairs(self.sort_class) do
                local data = self.crafting_hud.valid_recipes[recipe_name]
                if data and filter_recipes[recipe_name] ~= nil then
                    table.insert(self.filtered_recipes, data)
                end
            end
            if self.crafting_hud:IsCraftingOpen() then
                self:UpdateRecipeGrid(self.focus and not TheFrontEnd.tracking_mouse)
            else
                self.recipe_grid.dirty = true
            end
        else
            return ApplyFilters_old(self, ...)
        end
    end
end
